using AutoMapper;
using MediatR;
using RBAC.Api.Demain.ContentManagement;
using RBAC.Api.Erroc;
using RBAC.Api.Infaction;
using RBAC.Api.Writh.Command.ContentManagement;

namespace RBAC.Api.Writh.CommandHandler.ContentManagement
{
    /// <summary>
    /// 添加医院处理器
    /// </summary>
    public class AddHospitalCommandHandler : IRequestHandler<AddHospitalCommand, APIResult<object>>
    {
        private readonly IBaseRepositry<HospitalModel> baseRepositry;
        private readonly IMapper mapper;

        public AddHospitalCommandHandler(IBaseRepositry<HospitalModel> baseRepositry, IMapper mapper)
        {
            this.baseRepositry = baseRepositry;
            this.mapper = mapper;
        }

        public async Task<APIResult<object>> Handle(AddHospitalCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = ResultCode.Success;
            result.Message = "添加医院成功";

            var model = mapper.Map<HospitalModel>(request);

            await baseRepositry.Add(model);

            return await Task.FromResult(result);
        }
    }
}